<?php

namespace addons\zzyy\controller\api;

use app\admin\model\Feature;
use app\admin\model\zzyy\ZzyyFeature;
use app\admin\model\zzyy\ZzyyRoom;
use app\admin\model\zzyy\ZzyyStore;

class Store extends \app\common\controller\Api
{
    protected $noNeedLogin = ['*'];

    public function all()
    {
        $stores = ZzyyStore::all();
        $stores = array_map(function ($e) {
            $e->store_bannerimage = cdnurl($e->store_bannerimage, true);
            $e->store_slideimages = (function ($value) {
                $rows = explode(',', $value);
                return array_map(function ($e) {
                    return cdnurl($e, true);
                }, $rows);
            })($e->store_slideimages);
            $e->room_count = ZzyyRoom::where('store_id', $e->id)->count();
            return $e;
        }, $stores);

        $this->success('OK', $stores);
    }

    public function baseinfo()
    {
        $id = $this->request->get('id');

        $store = \addons\zzyy\module\Store::getStoreFormatInfo($id);

        $rooms = ZzyyRoom::where('store_id', $store->id)->select();
        $store->zzyyrooms = array_map(function ($e) {
            return \addons\zzyy\module\Room::getRoomFormatInfo($e->id);
        }, $rooms);


        $this->success('OK',  $store);
    }
}
